using System;
using System.IO;
using System.Reflection;
using System.Xml;
using XmlObjects;
using XmlObjects.XmlDocumentMarkup;
using MbUnit.Framework;

namespace UnitTests
{
	[TestFixture]
	public class TestXmlWriter
	{
		[Test]
		public void TestFileInfoToString()
		{
			FileInfo fileInfo = new FileInfo(Path.GetTempFileName());
			DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetTempPath());

			Console.WriteLine(fileInfo);
			Console.WriteLine(directoryInfo);
			
		}


		[Test]
		public void TestXmlDecorationReaderHandlesAttribute()
		{
			PropertyInfo propertyInfo = somethingDocument.GetType().GetProperty("AttributeOne");

			IXmlDocumentPropertyReader reader = new AttributePropertyReader(propertyInfo);
			Assert.IsTrue(DocumentPropertyReader.IsDecorated(propertyInfo));

			XmlNode node = GetNode();
			reader.WriteXml(node, somethingDocument, node.OwnerDocument);
			Assert.AreEqual(attributeOne, node.Attributes["attributeOne"].Value);
		}
		[Test]
		public void TestXmlDecorationReaderHandlesInt()
		{
			PropertyInfo propertyInfo = somethingDocument.GetType().GetProperty("AttributeOne");
			IXmlDocumentPropertyReader reader = new AttributePropertyReader(propertyInfo);

			XmlNode node = GetNode();
			reader.WriteXml(node, somethingDocument, node.OwnerDocument);
			Assert.AreEqual(attributeOne, node.Attributes["attributeOne"].Value);
		}

		private XmlNode GetNode()
		{
			return new XmlDocument().CreateElement("element");
		}

		[Test]
		public void TestOne()
		{
			XmlDocument document = somethingDocument.CreateXmlDocument();

			Assert.IsNotNull(document.SelectSingleNode("/myXmlDocument"));
		}

		private Something somethingDocument;
		private string attributeOne = "one";
		private string attributeTwo = "two";
		private string elementOne = "elementOne";
		private int attributeThree = 2;

		[SetUp]
		public void SetUp()
		{
			somethingDocument = new Something(attributeOne, attributeTwo, elementOne);
			somethingDocument.AttributeThree = attributeThree;
		}

		[TearDown]
		public void TearDown()
		{
		}

		[XmlElement("myXmlDocument")]
		public class Something : DocumentElement
		{
			private string attributeOne;
			private string attributeTwo;
			private string elementOne;


			public Something(string attributeOne, string attributeTwo, string elementOne)
			{
				this.attributeOne = attributeOne;
				this.attributeTwo = attributeTwo;
				this.elementOne = elementOne;
			}

			[XmlAttribute("attributeOne")]
			public string AttributeOne
			{
				get { return attributeOne; }
				set { attributeOne = value; }
			}

			[XmlAttribute("attributeTwo")]
			public string AttributeTwo
			{
				get { return attributeTwo; }
				set { attributeTwo = value; }
			}

			private int attributeThree;

			[XmlAttribute("integer")]
			public int AttributeThree
			{
				get { return attributeThree; }
				set { attributeThree = value; }
			}

			[XmlElement("elementOne")]
			public string ElementOne
			{
				get { return elementOne; }
				set { elementOne = value; }
			}
		}
	}
}